package com.daedalus.Gui.other.SimpleGame;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JSplitPane;


public class MainPanel extends JSplitPane{
	GamePanel game;
	EventsPanel events;
	
	public MainPanel(){
		super(JSplitPane.VERTICAL_SPLIT);
		setSize(400,600);
		super.setDividerLocation(0.6);
		super.setDividerSize(2);
		this.setContinuousLayout(true);
		
		
		game=new GamePanel();
		events=new EventsPanel();
		
		this.setTopComponent(game);
		this.setBottomComponent(events);
		
		eventsHandler handler = new eventsHandler();
		
		events.up.addActionListener(handler);
		events.down.addActionListener(handler);
		events.left.addActionListener(handler);
		events.right.addActionListener(handler);
	}

	private class eventsHandler implements ActionListener{

		@Override
		public void actionPerformed(ActionEvent e) {
			if(e.getSource()==events.up)	game.update(game.player.getX(),game.player.getY()-50);
			if(e.getSource()==events.down) 	game.update(game.player.getX(), game.player.getY()+50);
			if(e.getSource()==events.left)	game.update(game.player.getX()-50, game.player.getY());
			if(e.getSource()==events.right)	{game.update(game.player.getX()+50, game.player.getY());}
		}
		
	}
}
